package tests;

///*
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.OrderingComparison.lessThan;
import static org.hamcrest.number.OrderingComparison.greaterThan;
//*/
import static org.junit.Assert.*;
import org.junit.*;
import main.SquareRoot;

public class SquareRootTest {
	private static final double EPSILON = .000001;

	@Test
	public void positive() {
		assertTrue(SquareRoot.sqrt(4)>0);
		assertTrue(SquareRoot.sqrt(0)>=0);
	}

	@Test
	public void precise() {
		assertEquals(SquareRoot.sqrt(4), Math.sqrt(4), EPSILON);
		assertEquals(SquareRoot.sqrt(169), Math.sqrt(169), EPSILON);
		assertEquals(SquareRoot.sqrt(194728), Math.sqrt(194728), EPSILON);
	}

	///*@Test
	public void belowOne() {
		for (double x=0.001; x<1; x+=.01)
			assertThat(SquareRoot.sqrt(x),
				is(lessThan(1.0)));
	}

	@Test
	public void aboveOne() {
		for (double x=1.001; x<10; x+=1)
			assertThat(SquareRoot.sqrt(x),
				is(greaterThan(1.0)));
	}
	//*/

	@Test
	public void boundaries() {
		assertEquals(SquareRoot.sqrt(0), 0, EPSILON);
		assertEquals(SquareRoot.sqrt(1), 1, EPSILON);
	}

	@Test(timeout=1000)
	public void big() {
		assertEquals(SquareRoot.sqrt(1E15), Math.sqrt(1E15), EPSILON);
	}

	@Test(expected=IllegalArgumentException.class)
	public void bad() {
		SquareRoot.sqrt(-1);
	}
}
